window.onload = function () {
    // 对象解构
    //let [a,b,c] = [1,2,3];
    //let {name,id} = {id:1,name:'jack'};

    let obj1 = {
        age:18,
        value:'v1',
        name:'jack',
        msg:'12345'
    };
    // let $id = obj1.id;
    // let _age = obj1.age;
    // let v = obj.value;

    let {value:v="v",age:_age,id:$id=1} = obj1;
    console.log($id)  //1

    //别名  && 默认值
    //扩展题：
    var {x:a = 10} = {};
    console.log(x); //x is not defined
    console.log(a);//ok

    var {x:a,y:b = 5} = {x:1,y:null};
    console.log(a,b) //a=1;b = null

    var {x:a=2,y:b = 5} = {x:undefined,y:null};
    console.log(a,b) //a=2;b = null


    //常见对象解构的写法
    // import {ref} from 'vue';  //import obj from 'vue'   obj.ref; obj.a
    // import React,{useState} from 'vue';

    // const fn = function({count,num}){
    //     return count+num
    // };
    // const fn = ({count,num}) =>count+num;
    // let obj2 = {count:100,num:200};
    // fn(obj2)

    //
    let obj3 = {
        id:1,
        msg:'error',
        arr:[5,6,7,8],
        o:{v:1}
    };
    //求obj3对象中id和arr的和 1+5+6+7+8
    // function fn({id,arr}){
    //     let i = id;
    //     for(var v of arr){
    //         i+=v
    //     };
    //     return i
    // };
    // fn(obj3)
    //reduce()
    const sum = ({id,arr})=>arr.reduce((total,cur)=>total+cur,id);
    console.log(sum(obj3));  //27

    // let {o:{v:value=1}} = obj3;
    // console.log(value) //1

    // axios.get().then(res=>{
    //     let {data:{result:a=1},code,msg} = res;
    //     console.log(a)
    // })









}



